//Based on the jQuery Plugin notifier.js (http://srirangan.net/2011-11-notifier-js-elegant-javascript-notifications)
// and die Pull request from Hello71 on GitHub (https://github.com/Hello71/notifer.js/tree/patch-1)
function Info(container) {

	var defined = function (obj) {
	  return (typeof obj !== "undefined");
	};
	this.config = {
	defaultTimeout: 2500,
	icons: {
		info: "images/info.png",
		warn: "images/warn.png",
		alert: "images/alert.png",
		success: "images/success.png",
		defaultIcon: "images/default.png"
	}
	};
	this.notify = function () {
	var options = {};
	if (typeof arguments[0] === "string") {
		options.message = arguments[0];
		if (typeof arguments[1] === "string") {
			options.title = arguments[1];
		}
		if (typeof arguments[2] === "string") {
			options.icon = arguments[2];
		}
		if (typeof arguments[3] === "number") {
			options.timeout = arguments[3];
		}
	} else {
		options = arguments[0];
	}
	var notification = $("<div>", {
		"class": "notification"
	});

	var timeout = options.timeout || this.config.defaultTimeout;
	var icon = options.icon || this.config.icons.defaultIcon;

	if (defined(icon)) {
	  $("<img>", {
		src: icon,
		
		"class": "notification-icon"
	  }).appendTo(notification);
	}

	var textElement = $("<div>", {
		"class": "notification-text"
	}).appendTo(notification);

	if (defined(options.title)) {
	  var title = $("<div>", {
		"class": "notification-title"
	  }).appendTo(textElement);
	  if (typeof options.message === "string") {
		title.text(options.title);
	  } else {
		title.append(options.title);
	  }
	}

	if (defined(options.message)) {
	  var message = $("<div>", {
		"class": "notification-message"
	  }).appendTo(textElement);
	  if (typeof options.message === "string") {
		message.text(options.message);
	  } else {
		message.append(options.message);
	  }
	}
	
	//Display notification
	notification
		.prependTo(container)
		.fadeIn('slow')
		.delay(timeout)
		.fadeOut('slow');

	};

	var notifier = function (type) {
		return function (opts) {
		  if (typeof opts !== "object") {
			var args = $.extend(true, [], arguments);
			args[2] = this.config.icon[type];
			this.notify.apply(this, args);
		  } else {
			var options = opts;
			options.icon = this.config.icon[type];
			this.notify(opts);
		  }
		};
	};
	this.info = notifier("info");
	this.warn = notifier("warn");
	this.warning = this.warn;
	this.alert = notifier("alert");
	this.success = notifier("success");
}
